/*
5_SecondStageFigures.do

Creates all second stage coefficient plots


"Human Capital and Climate Change", 
	by Noam Angrist, Kevin Winseck, Harry Patrinos, and Joshua Graff Zivin.
		
Inputs:
	Cleaned_ESS_withFirstStage.dta
Outputs:
	Figure2.png
	FigureA3.png
	

*/


**************************** Set up data ****************************

global clustervar "cntryXlaw"

use "Cleaned_ESS_withFirstStage.dta", clear

drop if mi(minEdu)
* Drop if missing CSL data




eststo clear


********************************************************************************
*** Figure 2: Standardized outcome indices
********************************************************************************

foreach var in "beliefs" "behaviors" "policy" "voting" {
	eststo `var'_main       : ivregress 2sls `var'_proenv_sd (eduyrs_wins=reform_pos_sig_* reform_pos_only_* reform_only_*) ///
												      yrbrn  i.cntry_numeric if in_sample==1 & in_pooled==1      , vce(cluster $clustervar)
	gen main_sample = e(sample)
	eststo `var'_ols        : regress        `var'_proenv_sd eduyrs_wins                             yrbrn  i.cntry_numeric if in_sample==1 & in_pooled==1 &main_sample==1     , vce(cluster $clustervar)
	drop main_sample
}
		
coefplot ///
	(beliefs_ols        , msymbol(X) ciopts(color(maroon)) mcolor(maroon)) /// 
	(beliefs_main       , msymbol(o) ciopts(color(navy)) mcolor(navy)) /// 
	(behaviors_ols        , msymbol(X) ciopts(color(maroon)) mcolor(maroon)) /// 
	(behaviors_main       , msymbol(o) ciopts(color(navy)) mcolor(navy)) /// 
	(policy_ols        , msymbol(X) ciopts(color(maroon)) mcolor(maroon)) /// 
	(policy_main       , msymbol(o) ciopts(color(navy)) mcolor(navy)) /// 
	(voting_ols        , msymbol(X) ciopts(color(maroon)) mcolor(maroon)) /// 
	(voting_main       , msymbol(o) ciopts(color(navy)) mcolor(navy)) ///
	, vertical  ///
	 groups(beliefs_ols beliefs_main beliefs_squared beliefs_yrFE beliefs_main_pooled beliefs_alt = "Beliefs Index" ///
		behaviors_ols behaviors_main behaviors_squared behaviors_yrFE behaviors_main_pooled behaviors_alt = "Behaviors Index" ///
		policy_ols policy_main policy_squared policy_yrFE policy_main_pooled policy_alt = "Policy Index" ///
		voting_ols voting_main voting_squared voting_yrFE voting_main_pooled voting_alt = "Green Voting" ) ///
	 coeflabels(beliefs_ols=" " beliefs_main=" " beliefs_squared=" " beliefs_yrFE=" " beliefs_main_pooled=" " beliefs_alt=" " ///
		behaviors_ols=" " behaviors_main=" " behaviors_squared=" " behaviors_yrFE=" " behaviors_main_pooled=" " behaviors_alt=" " ///
		policy_ols=" " policy_main=" " policy_squared=" " policy_yrFE=" " policy_main_pooled=" " policy_alt=" " ///
		voting_ols=" " voting_main=" " voting_squared=" " voting_yrFE=" " voting_main_pooled=" " voting_alt=" " ) ///
	keep(eduyrs_wins) swapnames aseq ci(90) /// 
	xline(3 6 9 /*7 14 21*/, lpattern(dash) lcolor(black)) title("Outcome Indices")  /// 
	ytitle("Effect Size (Standard Deviations)") offset(0) ///
	/*yscale(range(-0.25 0.25)) ylabel(-0.2(0.1)0.2, format(%9.1f))*/  yline(0, lcolor(black)) ///
	graphregion(color(white)) legend( order(2 "OLS Estimate" 4 "Main IV Specification" ) cols(2)) mlabel format(%9.3f) mlabcolor(black)
		
graph export "Figure2.png", replace			
		
		
********************************************************************************
*** Appendix Figure A3: Robustness checks on outcome indices
********************************************************************************
gen yr_binned = yrbrn
replace yr_binned = 1920 if yr_binned<1920


eststo clear

foreach var in "beliefs" "behaviors" "policy" "voting" {
	eststo `var'_main       : ivregress 2sls `var'_proenv (eduyrs_wins=reform_pos_sig_* reform_pos_only_* reform_only_*) ///
												      yrbrn b2.cntry_numeric if in_sample==1 & in_pooled==1      , vce(cluster $clustervar)
	eststo `var'_quadratic    : ivregress 2sls `var'_proenv (eduyrs_wins=reform_pos_sig_* reform_pos_only_* reform_only_*) ///
												      yrbrn yr2 b2.cntry_numeric if in_sample==1 & in_pooled==1      , vce(cluster $clustervar)
	eststo `var'_cubic    : ivregress 2sls `var'_proenv (eduyrs_wins=reform_pos_sig_* reform_pos_only_* reform_only_*) ///
												      yrbrn yr2 yr3 b2.cntry_numeric if in_sample==1 & in_pooled==1      , vce(cluster $clustervar)												      
	eststo `var'_yrFE       : ivregress 2sls `var'_proenv (eduyrs_wins=reform_pos_sig_* reform_pos_only_* reform_only_*) ///
												      i.yr_binned                b2.cntry_numeric if in_sample==1 & in_pooled==1 , vce(cluster $clustervar)
	eststo `var'_main_pos_sig: ivregress 2sls `var'_proenv (eduyrs_wins=reform_pos_sig_*)          yrbrn  b2.cntry_numeric if in_sample==1 & in_pos_sig==1 , vce(cluster $clustervar)
	eststo `var'_main_pos: ivregress 2sls `var'_proenv (eduyrs_wins=reform_pos_sig_* reform_pos_only_*)          yrbrn  b2.cntry_numeric if in_sample==1 & in_pos==1 , vce(cluster $clustervar)
	eststo `var'_alt        : ivregress 2sls `var'_proenv (eduyrs_wins=b2.cntry_numeric#c.minEdu) yrbrn  b2.cntry_numeric if in_sample==1 & in_pooled==1 , vce(cluster $clustervar)
	
}


coefplot ///
	(beliefs_main       , msymbol(o) ciopts(color(navy)) mcolor(navy)) /// 
	(beliefs_quadratic   , msymbol(Oh) ciopts(color(maroon)) mcolor(maroon)) /// 
	(beliefs_cubic, msymbol(O) ciopts(color(mint)) mcolor(mint)) /// 
	(beliefs_yrFE       , msymbol(d) ciopts(color(orange)) mcolor(orange)) /// 
	(beliefs_main_pos_sig    , msymbol(t) ciopts(color(pink)) mcolor(pink)) /// 
	/*(beliefs_main_pos  , msymbol(s) ciopts(color(blue)) mcolor(blue))*/ /// 
	(beliefs_alt  , msymbol(X) ciopts(color(gray)) mcolor(gray)) /// 
	(behaviors_main       , msymbol(o) ciopts(color(navy)) mcolor(navy)) /// 
	(behaviors_quadratic   , msymbol(Oh) ciopts(color(maroon)) mcolor(maroon)) /// 
	(behaviors_cubic, msymbol(O) ciopts(color(mint)) mcolor(mint)) /// 
	(behaviors_yrFE       , msymbol(d) ciopts(color(orange)) mcolor(orange)) /// 
	(behaviors_main_pos_sig    , msymbol(t) ciopts(color(pink)) mcolor(pink)) /// 
	/*(behaviors_main_pos  , msymbol(s) ciopts(color(blue)) mcolor(blue))*/ /// 
	(behaviors_alt  , msymbol(X) ciopts(color(gray)) mcolor(gray)) /// 
	(policy_main       , msymbol(o) ciopts(color(navy)) mcolor(navy)) /// 
	(policy_quadratic   , msymbol(Oh) ciopts(color(maroon)) mcolor(maroon)) ///
	(policy_cubic, msymbol(O) ciopts(color(mint)) mcolor(mint)) ///
	(policy_yrFE       , msymbol(d) ciopts(color(orange)) mcolor(orange)) /// 
	(policy_main_pos_sig    , msymbol(t) ciopts(color(pink)) mcolor(pink)) /// 
	/*(policy_main_pos  , msymbol(s) ciopts(color(blue)) mcolor(blue))*/ /// 
	(policy_alt  , msymbol(X) ciopts(color(gray)) mcolor(gray)) /// 
	(voting_main       , msymbol(o) ciopts(color(navy)) mcolor(navy)) /// 
	(voting_quadratic   , msymbol(Oh)  ciopts(color(maroon)) mcolor(maroon)) ///
	(voting_cubic, msymbol(O) ciopts(color(mint)) mcolor(mint)) /// 
	(voting_yrFE       , msymbol(d) ciopts(color(orange)) mcolor(orange)) /// 
	(voting_main_pos_sig    , msymbol(t) ciopts(color(pink)) mcolor(pink)) /// 
	/*(voting_main_pos  , msymbol(s) ciopts(color(blue)) mcolor(blue))*/ /// 
	(voting_alt  , msymbol(X) ciopts(color(gray)) mcolor(gray)) /// 
	 , vertical  ///
	 groups(beliefs_main beliefs_quadratic beliefs_cubic beliefs_yrFE beliefs_main_pos_sig /*beliefs_main_pos*/ beliefs_alt = "Beliefs Index" ///
		behaviors_main behaviors_quadratic behaviors_cubic behaviors_yrFE behaviors_main_pos_sig /*behaviors_main_pos*/ behaviors_alt = "Behaviors Index" ///
		policy_main policy_quadratic policy_cubic policy_yrFE policy_main_pos_sig /*policy_main_pos*/ policy_alt  = "Policy Index" ///
		voting_main voting_quadratic voting_cubic voting_yrFE voting_main_pos_sig /*voting_main_pos*/ voting_alt = "Green Voting" ) ///
	 coeflabels(beliefs_main=" " beliefs_quadratic=" " beliefs_cubic=" " beliefs_yrFE=" " beliefs_main_pos_sig=" " /*beliefs_main_pos=" "*/ beliefs_alt=" " ///
	 behaviors_main=" " behaviors_quadratic=" " behaviors_cubic=" " behaviors_yrFE=" " behaviors_main_pos_sig=" " /*behaviors_main_pos=" "*/ behaviors_alt=" " ///
	 policy_main=" " policy_quadratic=" " policy_cubic=" " policy_yrFE=" " policy_main_pos_sig=" " /*policy_main_pos=" "*/ policy_alt=" " ///
	 voting_main=" " voting_quadratic=" " voting_cubic=" " voting_yrFE=" " voting_main_pos_sig=" " /*voting_main_pos=" "*/ voting_alt=" ") ///
	keep(eduyrs_wins) swapnames aseq  ci(90)  /// 
	xline(7 14 21 /*8 16 24*/, lpattern(dash) lcolor(black)) title("Outcome Indices")  /// 
	ytitle("Effect Size") offset(0) ///
	yline(0, lcolor(black)) ///
	graphregion(color(white)) legend( order(2 "Main Specification" 4 "Quadratic Time Trend" 6 "Cubic Time Trend" 8 "Year Fixed Effects" 10 "Pos. + Sig. 1st Stages" 12 /*"Positive 1st Stages" 14*/ "Alternate Instrument") cols(2)) xla(, notick) 

graph export "FigureA3.png", replace			
		
		
	
